// pages/mypractice/mypractice.js
import { URL, ajax, Toast, getUser } from '../../utils/index.js'
Page({
  data: {
    itemTitle: '全部场景',
    modelId: null,
    practiceHistoryList:[],
    option1: [
      { text: '品牌介绍场景', value: 0 },
      { text: '项目介绍场景', value: 1 },
      { text: '区域对比场景', value: 2 }
    ],
    option:[],
  },
  queryModelList(){
    ajax.loading()
    return new Promise((resolve, reject) => {
        ajax.post('/applet/practice/queryModelList').then(res => {
            if (res.data.code == 1) {
                res.data.data.modelList.unshift({modelId:null,modelName:"全部场景",wjgNum:0})
                this.setData({
                  option: res.data.data.modelList
                }),ajax.toast.clear(),resolve(res)
            } else ajax.toast.fail(res.data.msg), reject(res)
        }).catch(e => (ajax.toast.fail('接口错误onload'), reject(e), console.log(e)))
    })
  },
  queryAssessList(){
    ajax.loading()
    return new Promise((resolve, reject) => {
        ajax.post('/applet/practice/queryPracticeHistoryList',{modelId:this.data.modelId}).then(res => {
            if (res.data.code == 1) {
                resolve(res)
                this.setData({
                  practiceHistoryList : res.data.data.practiceHistoryList
                })
                ajax.toast.clear()
            } else ajax.toast.fail(res.data.msg), reject(res)
        }).catch(e => (ajax.toast.fail('接口错误onload'), reject(e), console.log(e)))
    })
  },
  vancellclick(e){
    this.setData({
      modelId: e.currentTarget.dataset.option.modelId
    })
    this.selectComponent('#item').toggle(),this.queryAssessList()
  },
  viewto(e){
    let {id} = e.currentTarget.dataset
    wx.navigateTo({url: `/pages/practicedetails/practicedetails?id=${id}`})
  },
  onLoad: function (options) {
    this.queryModelList(),this.queryAssessList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})